<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="/struts-tags" prefix="s"%>

<link rel="stylesheet" href="styles/form-input.css" type="text/css" media="all" />
<link rel="stylesheet" href="styles/displaytag.css" type="text/css" media="all" />
<link type="text/css" rel="stylesheet" href="js/jquery/css/ui-lightness/jquery-ui-1.8.16.custom.css"/>
<script type="text/javascript" src="js/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
   		$("button").button();
 	});

	function CheckAll(fmobj) {
		for (var i=0;i<fmobj.elements.length;i++) {
			var e = fmobj.elements[i];
			if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
				e.checked = fmobj.allbox.checked;
			}
		}
	};
</script>

	<div class="error-text"><s:actionerror /></div>
	<div class="error-text"><s:fielderror /></div>
	<div class="message-text"><s:actionmessage /></div>
	
	<div>
		<h3>Maintain Branch</h3>
		<s:form theme="simple" validate="true" method="POST" >
			<s:hidden name="branchId"/>
			<fieldset style="width:800px">
            	<legend><h3>Branch</h3></legend>
           		<table cellpadding="3" class="table-form">
           			<s:if test="branchId==0L">
           				<tr><td>Branch Code</td><td><s:textfield name="branchCode" maxlength="4"/>*</td></tr>
           			</s:if>
					<s:else>
						<s:hidden name="branchCode" />
						<tr><td>Branch Code</td><td><s:textfield name="branchCode" readonly="true"/></td></tr>
					</s:else>
					<tr><td>Branch Name</td><td><s:textfield name="branchName" size="50"/>*</td></tr>
					<tr><td>Branch Email</td><td><s:textfield name="branchEmail" size="50"/></td></tr>
					<tr><td>Area</td><td><s:select name="areaId" list="areas" headerKey="-1" headerValue="Select Area" listKey="id" listValue="name"/>*</td></tr>
					<tr></tr>
		            <s:if test="branchId==0L">
						<tr><td></td><td><s:submit type="button" action="addOrUpdateBranch">SAVE</s:submit>
					</s:if>
					<s:else>
						<tr><td></td><td>
						<s:submit type="button" action="addOrUpdateBranch">UPDATE</s:submit>
						<button type="button" onclick="window.location.href='listBranch'">CANCEL</button>
					</s:else>
				</table>
			</fieldset>			
		</s:form>
	</div>
	<br>
	<br>
	<br>
	<div>
		<s:form name="form_table" method="POST" action="removeBranchs" theme="simple" onsubmit="return confirm('Delete these branchs?');">
			<c:set var="checkAll">
	    		<input type="checkbox" name="allbox" onclick="CheckAll(document.form_table)" />
			</c:set>
			<display:table 	id			= "bm"
	              			name       	= "${branchModels}"
	             			pagesize   	= "10" style="width: 800px"
	              			requestURI 	= "/listBranch" class="display" decorator="com.btpn.custody.web.m001.decorator.BranchDecorator">
	              	              	
	            	<c:url var="urlEditBranch" value="editBranch">
						<c:param name="id" value="${bm.branchId}"/>
					</c:url>
					
	            <display:column title	= "${checkAll}"
	            				property= "checkbox" style="width: 6%" />
	            				
	   			<display:column title	= "NO." style="width: 8%"
	              				value   = "${bm_rowNum}" />
	              				   
			   	<display:column title 	= "Branch Code" style="width: 15%" 
			   					nulls	= "false" sortable= "true" >
			   		<a href="${urlEditBranch}">${bm.branchCode}</a>
			   	</display:column>
			   	
			   	<display:column title 	= "Nama Cabang"
			   					nulls	= "false" sortable= "true" >			   		
					<a href="${urlEditBranch}">${bm.branchName}</a>
				</display:column>
			   	
			   	<display:column title 	= "Area"
			   					nulls	= "false" sortable= "true" >
			   		<c:url var="urlEditArea" value="editArea">
						<c:param name="id" value="${bm.areaId}"/>
					</c:url>
					<a href="${urlEditArea}">${bm.areaName}</a> 
			   	</display:column>				
			   	
			   	<display:column title 	= "Region"
			   					nulls	= "false" sortable= "true" >
			   		<c:url var="urlEditRegion" value="editRegion">
						<c:param name="id" value="${bm.regionId}"/>
					</c:url>
					<a href="${urlEditRegion}">${bm.regionName}</a> 
			   	</display:column>
			   	
			</display:table>
			
			<c:if test="${branchModels.size()>0}" >
	          	<button type="submit" >DELETE</button>
	        </c:if>
		</s:form>
	</div>